﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.OleDb;
using System.Data;

/// <summary>
///WebSet 的摘要说明
/// </summary>
public static class WebSet
{
    public static string GetSingleValue(string Wkey)
    {
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Wvalue from Webset where Wkey = @Wkey", myconn);
        mycmd.Parameters.AddWithValue("@Wkey", Wkey);
        //mycmd.Parameters.AddWithValue("@lg", lg);
        string dr = "";
        try
        {
            myconn.Open();
            dr = mycmd.ExecuteScalar().ToString();
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            myconn.Close();
        }
        return dr;
    }
    //获取产品列表1
    public static string GetProList()
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Ptypeid,Pname from Ptype Order BY  Psort DESC", myconn);
        OleDbDataReader DR = null;
        try
        {
            myconn.Open();
            DR = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        while (DR.Read())
        {
            //if (DR["Ptypeid"].ToString() == "3")
            //{
            //    str += "<div class=\"xuankuang\"><div class=\"xuankuang3\">" + DR["Pname"].ToString() + "</div>";
            //}
            //else
            //{

            str += "<ul style=\"margin:5px 0 0 25px;\"><span><a href=\"#\">" + DR["Pname"].ToString() + "</a></span>";
            //}
            //str += "<ul>";
            OleDbCommand mycmd1 = new OleDbCommand("select Pid,Ptypeid,HtmlUrl,Pname from [Product] Order BY  Psort DESC", myconn);
            OleDbDataReader DR1 = null;
            DR1 = mycmd1.ExecuteReader(CommandBehavior.CloseConnection);
            int s = 0;
            while (DR1.Read())
            {
                

                if (DR["Ptypeid"].ToString() == DR1["Ptypeid"].ToString())
                {
                    if (s < 12)
                    {
                        str += "<li><a href=\"" + DR1["HtmlUrl"].ToString() + "\"> " + DR1["Pname"].ToString() + "</a></li>";
                        s++;
                    }
                }
               
            }

            str += "</ul>";
        }
        
        DR.Close();
        DR.Dispose();
        return str;
    }
    //获取产品列表2 生成静态页面时用到
    public static string GetProList2()
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Ptypeid,Pname from Ptype Order BY  Psort DESC", myconn);
        OleDbDataReader DR = null;
        try
        {
            myconn.Open();
            DR = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        //int i = 1;
        while (DR.Read())
        {
            str += "<li><a href=\"#\">" + DR["Pname"].ToString() + "</a></li>";
            //str += "<li><a href=\"#\"  onclick=\"DoMenu('ChildMenu" + i + "')\">" + DR["Pname"].ToString() + "</a><ul id=\"ChildMenu" + i + "\" class=\"collapsed\">";
    
            OleDbCommand mycmd1 = new OleDbCommand("select Pid,Ptypeid,HtmlUrl,Pname from [Product] Order BY  Psort DESC", myconn);
            OleDbDataReader DR1 = null;
            DR1 = mycmd1.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR1.Read())
            {

                if (DR["Ptypeid"].ToString() == DR1["Ptypeid"].ToString())
                {
                    str += "<span><a href=\"" + DR1["HtmlUrl"].ToString() + "\"> " + DR1["Pname"].ToString() + "</a></span>";
                }

            }

            //str += "</ul></li>";
            //i++;
        }

        DR.Close();
        DR.Dispose();
        return str;
    }
    //获取产品列表2 生成静态页面时用到 连接目录向上一级
    public static string GetProList2lujing()
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Ptypeid,Pname from Ptype Order BY  Psort DESC", myconn);
        OleDbDataReader DR = null;
        try
        {
            myconn.Open();
            DR = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }

        while (DR.Read())
        {


            OleDbCommand mycmd1 = new OleDbCommand("select Top 30 Pid,Ptypeid,HtmlUrl,Pname from [Product] Order BY  Psort DESC", myconn);
            OleDbDataReader DR1 = null;
            DR1 = mycmd1.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR1.Read())
            {

                if (DR["Ptypeid"].ToString() == DR1["Ptypeid"].ToString())
                {
                    str += "<li><a href=\"../" + DR1["HtmlUrl"].ToString() + "\"> " + DR1["Pname"].ToString() + "</a></li>";
                }

            }
        }

        DR.Close();
        DR.Dispose();
        return str;
    }
    //获取产品列表 根据产品大类
    public static string GetProListForType(int Type)
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Pid,Ptypeid,HtmlUrl,Pname,Psimg from [Product] where Ptypeid="+Type+" Order BY  Psort DESC", myconn);
        OleDbDataReader DR = null;
        try
        {
            myconn.Open();
            DR = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        while (DR.Read())
        {
            //str += "<li><a href=\"" + DR["HtmlUrl"].ToString() + "\"><img src=\"~/ProductImages/" + DR["Psimg"].ToString() + "\" width=\"125\" height=\"124\" alt=\"" + DR["Pname"].ToString() + "\" /></a><br /><p><a href=\"" + DR["HtmlUrl"].ToString() + "\">" + DR["Pname"].ToString() + "</a></p><a href=\"" + DR["HtmlUrl"].ToString() + "#1\">产品介绍</a>　<a href=\"" + DR["HtmlUrl"].ToString() + "#2\">产品图片</a><br /><a href=\"" + DR["HtmlUrl"].ToString() + "#3\">工作原理</a>　<a href=\"" + DR["HtmlUrl"].ToString() + "#3\">技术参数</a></li>";
            str += "<a href=\"" + DR["HtmlUrl"].ToString() + "\">" + DR["Pname"].ToString() + "</a>";
        }

        DR.Close();
        DR.Dispose();
        return str;
    }
    //获取推荐产品
    public static string GetTopnPro(int n)
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Top " + n + " Pid,Ptypeid,HtmlUrl,Pname,Psimg,Pjj from [Product] Order BY Psort DESC", myconn);
        OleDbDataReader DR1 = null;
        try
        {
            myconn.Open();
            DR1 = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
        }

        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        while (DR1.Read())
        {
            //string jj = "";
            //if (DR1["Pjj"].ToString().Length > 40)
            //{
            //    jj = DR1["Pjj"].ToString().Substring(0, 39);
            //}
            //else
            //{
            //    jj = DR1["Pjj"].ToString();
            //}
            str += "<li><a href=\"" + DR1["HtmlUrl"].ToString() + "\"><img src=\"ProductImages/" + DR1["Psimg"].ToString() + "\" width=\"117\" height=\"115\" /><a href=\"" + DR1["HtmlUrl"].ToString() + "\">" + DR1["Pname"].ToString() + "</a></li>";
        }
        DR1.Close();
        DR1.Dispose();
        return str;
    }
    //获取最新新闻
    public static string GetTopnNews(int n,int zishu)
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Top " + n + " NID,Ntitle,HtmlUrl from [News] Order BY NID DESC", myconn);
        OleDbDataReader DR1 = null;
        try
        {
            myconn.Open();
            DR1 = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
        }

        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        while (DR1.Read())
        {
            string jj = "";
            if (DR1["Ntitle"].ToString().Length > zishu)
            {
                jj = DR1["Ntitle"].ToString().Substring(0, zishu - 1) ;
            }
            else
            {
                jj = DR1["Ntitle"].ToString();
            }
            str += "<li><a href=\"" + DR1["HtmlUrl"].ToString() + "\">" + jj + "</a></li>";
        }
        DR1.Close();
        DR1.Dispose();
        return str;
    }
    //获取关于我们列表
    public static string GetAboutList()
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Atitle,AID from [About] Order BY AID ASC", myconn);
        OleDbDataReader DR1 = null;
        try
        {
            myconn.Open();
            DR1 = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
        }

        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        while (DR1.Read())
        {
            str += "<a href=\"http://www.fuhepo.cn/about/?AID=" + DR1["AID"].ToString() + "\">" + DR1["Atitle"].ToString() + "</a>";
        }
        DR1.Close();
        DR1.Dispose();
        return str;
    }
    //关于我们 根据ID 获取标题
    public static string GetAboutForAid(int aid)
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Atitle from [About] Where AID=" + aid + "", myconn);

        try
        {
            myconn.Open();
            str = mycmd.ExecuteScalar().ToString();
        }

        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        myconn.Close();
        return str;
    }
    //关于我们 根据ID 获取内容
    public static string GetAboutConForAid(int aid)
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select Acontent from [About] Where AID=" + aid + "", myconn);

        try
        {
            myconn.Open();
            str = mycmd.ExecuteScalar().ToString();
        }

        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        myconn.Close();
        return str;
    }
    /// <summary>
    /// 获取产品类(ziduanming)根据产品类ID
    /// </summary>
    public static string GetProPTypeForPTypeId(int Ptypeid,string ziduanming)
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select " + ziduanming + " from [Ptype] Where Ptypeid=" + Ptypeid + "", myconn);
        try
        {
            myconn.Open();
            object obj = mycmd.ExecuteScalar();
            if (obj != null)
            {
                str = obj.ToString();
            }
        }

        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        myconn.Close();

        return str;
    }
    /// <summary>
    /// 获取产品(ziduanming)根据产品类ID
    /// </summary>
    public static string GetProForPid(int Pid, string ziduanming)
    {
        string str = "";
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand("select " + ziduanming + " from [Product] Where Pid=" + Pid + "", myconn);
        try
        {
            myconn.Open();
            object obj = mycmd.ExecuteScalar();
            if (obj != null)
            {
                str = obj.ToString();
            }
        }

        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        myconn.Close();

        return str;
    }
    public static OleDbDataReader GetDataReadeForSql(string sql)
    {
        OleDbConnection myconn = new OleDbConnection(DB.conn);
        OleDbCommand mycmd = new OleDbCommand(sql, myconn);
        OleDbDataReader dr = null;
        try
        {
            myconn.Open();
            dr = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
        }

        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }


        return dr;
    }
}